<%--
  Created by IntelliJ IDEA.
  User: 22328
  Date: 2021/2/11
  Time: 23:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>商品分类添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-form" onsubmit="return false">
            <div class="layui-form-item" style="display: none">
                <label for="id" class="layui-form-label">
                    ID
                </label>
                <div class="layui-input-inline" style="width: 200px">
                    <input type="text" id="id" name="id" value="${categoryInfo.id}"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="categoryName" class="layui-form-label">
                    分类名
                </label>
                <div class="layui-input-inline" style="width: 200px">
                    <input type="text" id="categoryName" name="categoryName" value="${categoryInfo.categoryName}"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="categoryDesc" class="layui-form-label">
                    描述
                </label>
                <div class="layui-input-inline" style="width: 200px">
                    <input type="text" id="categoryDesc" name="categoryDesc" value="${categoryInfo.categoryDesc}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                </label>
                <button id="add_btn" class="layui-btn">
                    修改
                </button>
            </div>
        </div>
    </div>
</div>
</body>
<script src="./js/jquery-3.1.0.min.js" type="text/javascript"></script>
<script>
    layui.use(['form', 'layer'], function () {
        var form = layui.form,
            layer = layui.layer;
    });
    $(function () {
        $("#add_btn").click(function () {
            var id = $("#id").val();
            var categoryName = $("#categoryName").val();
            var categoryDesc = $("#categoryDesc").val();
            $.ajax({
                url: "./updateCategory",
                type: "post",
                data: {
                    id:id,
                    categoryName:categoryName,
                    categoryDesc:categoryDesc
                },
                success: function (res) {
                    if (res.data === "修改成功") {
                        layer.alert("修改成功", {
                                icon: 6
                            },
                            function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                    } else {
                        layer.msg("修改失败");
                    }
                },
                error: function () {
                    alert("404.html页面");
                }
            });
        });
    });
</script>
</html>
